﻿using Newtonsoft.Json;
using SocketioTest.Common;
using SocketioTest.ViewModel;
using System;
using System.Windows;

namespace SocketioTest.View
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        public CommandBase Closewindoszhibo { get; set; }
        public Login()
        {
            this.DataContext = new LoginViewModel();

            InitializeComponent();

        }

    
        private void btnlogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var responseObj = HttpRequest_All.GoLogin(this.UserTextBox.Text, this.PwdTextBox.Text);

                Console.WriteLine(responseObj);
                HttpOutInfo.Login.Root list_responseObj = JsonConvert.DeserializeObject<HttpOutInfo.Login.Root>(responseObj);
                //MessageBox.Show(list_responseObj.msg);
                if (list_responseObj.code == 0)
                {
                    Global.uid = list_responseObj.data.id;
                    Global.name = list_responseObj.data.name;
                    Global.avatar = list_responseObj.data.avatar;
                    Global.access_token = list_responseObj.data.access_token;
                    new MainWindow().Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("服务器链接失败");
                Log.WriteLog(ex);
            }
        }
    }


}
